examples/userfs: use designated initializers for struct dirent#3554
Open
xiaoxiang781216 wants to merge 1 commit into
Open
examples/userfs: use designated initializers for struct dirent#3554xiaoxiang781216 wants to merge 1 commit into
xiaoxiang781216 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the examples/userfs in-memory directory table to use designated initializers for struct dirent so it remains correct even if the field order changes (e.g., with the addition of d_ino).
Changes:
- Converted
g_rootdir[]struct direntinitializers from positional to designated (.d_type,.d_name) forFile1–File3.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The g_rootdir[] table initialized each entry's struct dirent member
positionally as { DTYPE_FILE, "FileN" }, which assumes d_type is the
first field. This breaks when struct dirent gains the POSIX d_ino field
as its first member (see apache/nuttx: "fs/dirent: add d_ino member to
struct dirent"): the file-name string would be assigned to d_type,
producing -Wint-conversion warnings and an "initializer element is not
computable at load time" error.
Use designated initializers (.d_type / .d_name) so the table is robust
against the field order of struct dirent.
Also fix a 'Initiallly' typo in a nearby comment flagged by codespell.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
0977fec to
e71f819
Compare
acassis
approved these changes
Jun 21, 2026
simbit18
approved these changes
Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
userfsexample initialized eachg_rootdir[]entry'sstruct direntmember positionally as{ DTYPE_FILE, "FileN" }, whichassumes
d_typeis the first field ofstruct dirent.apache/nuttx PR #19179 ("fs: widen ino_t to uint32_t and add d_ino to
struct dirent") adds the POSIX
d_inomember as the first field ofstruct dirent. With that change the positional initializer assigns thefile-name string to
d_type(auint8_t), producing-Wint-conversionwarnings and anerror: initializer element is not computable at load time, which brokethe CI build.
This change converts the three initializers to designated initializers
(
.d_type/.d_name) so the table is robust against the field order ofstruct dirent.Impact
examples/userfsonly. No functional change; the samed_type/d_namevalues are assigned.
d_inois left zero-initialized, which is fine forthis in-memory test filesystem.
Testing
checkpatch.sh -f examples/userfs/userfs_main.c→ all checks pass.d_ino-firststruct direntcompiles cleanly with-Wall -Wextra -Werrorand assignsd_type=DTYPE_FILE,d_name="File1"as expected.Related
positional initializer; this PR fixes it. They should be merged together.